import {defineStore} from "pinia"

const useMusic = defineStore('music', {
    persist: {
        enabled: true, //开启数据持久化
        strategies: [
            {
                key: "music",//给一个要保存的名称
                storage: localStorage, //sessionStorage / localStorage 存储方式
            },
        ],
    },
    state: () => {
        return {
            musicinfo : {
                name:"",
                auther:"",
                url : "",
                id : "",
                pic : "",
                time:"",
                notNullLyricArr:[],
                timeList:[],
            },
            catelog:{},
            playlist:[],
            nextmusicmeth:1, /* 1顺序播放 2循环播放 3随机播放 */
        }
    },
    getters: {
        getmusicinfo(){
            return {
                ...this.musicinfo,
                timeList:this.musicinfo.timeList,
                notNullLyricArr:this.musicinfo.notNullLyricArr
            }
        },
        getnextmusicmeth(){
            return this.nextmusicmeth
        },
        getplaylist(){
            return this.playlist 
        }
    },
    actions:{
        /* 设置musicinfo */
        setcurrentmusicinfo(data){
            this.musicinfo = Object.assign(this.musicinfo,data)
        },
        setlyric(data){
            this.musicinfo.notNullLyricArr = data
        },
        settimeList(data){
            this.musicinfo.timeList = data
        },
        setcatelog(catelog){
             this.catelog = catelog
        },
        setnextmusicmeth(meth){
            this.nextmusicmeth = meth
        },
        setplaylist(playlist){
            this.playlist = playlist 
        }
    }
})

export default useMusic